
import fetchJson from './fetchJson'
import tools from './tools'
import Config from './config'
import eventBus from '../eventBus'
export default {
  start () {
    this.getFiberList()
  },

  addEl (vm, json) {
    eventBus.bus.$emit('showLoading')
    this.vm = vm
    var data = tools.jsonToStr(json)
    fetchJson.getJson({
      self: this,
      url: '/cable/saveasjson/?' + data,
      callback: this.callback,
      error: this.error
    })
  },
<<<<<<< HEAD

=======
  setLevel (data) {
    for (var i=0; i<data.length; i++) {
      console.log('data[i][level]:', data[i]['level'])
      if (data[i]['level'] === 1) {
        data[i]['level'] = '成功'
      } else {
        data[i]['level'] = '失败'
      }
    }
  },
>>>>>>> 118bfb24f1cbdee8aba2f4af5269fcf3bfe2e597
  refresh (json) {
    eventBus.bus.$emit('showLoading')
    var data = tools.jsonToStr(json)
    fetchJson.getJson({
      self: this,
      url: '/cable/updateasjson/?' + data,
      callback: this.reFreshcallback,
      error: this.error
    })
  },
  
  reFreshcallback () {
    eventBus.bus.$emit('hideLoading')
    if (json.code === 1) {
<<<<<<< HEAD
      eventBus.bus.$emit('getFiberList', json.items)
=======
      eventBus.bus.$emit('getFiberList', json)
>>>>>>> 118bfb24f1cbdee8aba2f4af5269fcf3bfe2e597
    } else {
      eventBus.bus.$message({
        message: json.message,
        type: 'warning'
      })
    }
  },

  callback (json) {
    eventBus.bus.$emit('hideLoading')
    if (json.code === 1) {
      this.fiberData.push(json.item)
      // eventBus.bus.$emit('getFiberList', json.items)
    } else {
      eventBus.bus.$message({
        message: json.message,
        type: 'warning'
      })
    }
  },

  error () {
    eventBus.bus.$emit('hideLoading')
  }
  
}
